package com.zzy.demo.web;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.zzy.demo.utils.Des;
import com.zzy.demo.utils.FastJsonUtil;
import com.zzy.demo.utils.bean.ParamsBean;



/**
 * 
 * @author guokaige
 *
 */
@RestController
@RequestMapping("/rest")
public class TestRestController {
	
	@Autowired
	RestTemplate restTemplate;

	@RequestMapping("/index")
	public String index(Model model) {
		
 		Map<String, String>   templateParamsMap=new HashMap<String, String>();
 		templateParamsMap.put("code", "4233");
 		String templateParams=FastJsonUtil.fastJsonSerialize(templateParamsMap);
 		String encodeParams=new Des().strEnc(templateParams, "topnet@123456", null, null);
		
		
		
		//访问restUrl
		 HttpHeaders headers = new HttpHeaders();
         headers.add("X-Auth-Token", UUID.randomUUID().toString());
         
         ParamsBean paramsBean=new ParamsBean();
         paramsBean.setAppKey("kevin");
         paramsBean.setAppSecret("kevin");
         paramsBean.setPhoneNums("18336465621");
         paramsBean.setTemplateCode("SMS_115385698");
         paramsBean.setTemplateParams(encodeParams);
         
         
         HttpEntity<ParamsBean> requestEntity = new HttpEntity<ParamsBean>(paramsBean, headers);
         
         String result = restTemplate.postForObject(
                 "http://localhost:8066/sendMsgOuter", requestEntity,
                 String.class);
         
		return result;
	}
	
	
	
	
	@PostMapping("/hello")
    public String hello(String data) {

        return "hello:"+data;
    }
	
	@RequestMapping("/welcome/{words}")
    public String welcome(@PathVariable String words) {
      
        return "welcome:"+words;
    }

	
}
